<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-01-06 13:50:12
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2023-11-10 10:14:58
 * @FilePath: \mould\src\views\pages\Supervision\Consumption.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div></div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav">
          <!-- 左侧 -->
          <div class="mechanism_nav_left" style="width: 100%">
            <vDatePicker
              :defaultDate="value2"
              @selectPickDate="selectTime"
              width="215px !important"
            >
            </vDatePicker>
            <el-select
              class="selectCondition"
              v-model="getList.fConstructionhorizon"
              placeholder="施工层位"
              @change="yj_searchForm(getList)"
            >
              <el-option
                v-for="v in sgcDataList"
                :key="v.fItemName"
                :label="v.fItemName"
                :value="v.fItemValue"
              >
              </el-option>
            </el-select>

            <el-select
              class="selectBhz"
              style="width: 160px"
              v-model="getList.fMixturetype"
              placeholder="沥青混合料类型"
              @change="yj_searchForm(getList)"
            >
              <el-option
                v-for="v in liqhDataList"
                :key="v.fItemName"
                :label="v.fItemName"
                :value="v.fItemValue"
              >
              </el-option>
            </el-select>
            <el-select
              class="selectBhz"
              style="width: 160px"
              v-model="getList.stationId"
              placeholder="所有拌和站"
              @change="selectBhz"
            >
              <el-option
                v-for="v in bhzDataList"
                :key="v.fItemName"
                :label="v.fItemName"
                :value="v.fItemValue"
              >
              </el-option>
            </el-select>
            <el-select
              class="selectBhz"
              v-model="getList.machineId"
              placeholder="所有拌和机"
              @change="yj_searchForm(getList)"
            >
              <el-option
                v-for="v in bhjDataList"
                :key="v.fItemName"
                :label="v.fItemName"
                :value="v.fItemValue"
              >
              </el-option>
            </el-select>
          </div>
          <!-- 顶部按钮 -->
          <div class="print"></div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <div class="" style="width: 100%; height: 100%">
          <!-- 按钮 -->
          <div class="tab">
            <div
              v-for="(data, index) in typeData"
              :key="data.value"
              @click="changeType($event, index)"
            >
              <div
                class="btn"
                :style="{
                  color:
                    data.show === true ? 'rgba(0, 117, 255, 1)' : '#343639',
                  background: data.show === true ? '#E0EFFF' : '#fff',
                }"
              >
                {{ data.text }}
              </div>
            </div>
          </div>

          <div class="charts" v-if="typeData[0].show">
            <!-- 油石比 -->
            <oilstoneCharts
              v-loading="chartsLoading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(0, 0, 0, 0.3)"
              :time1="this.value2[0]"
              :time2="this.value2[1]"
              :checkType="checkType"
              :commonData="tableData"
              @clickLegend="clickLegend"
            >
            </oilstoneCharts>
          </div>

          <div class="charts" v-if="typeData[1].show">
            <!-- 温度曲线 -->
            <materialCharts
              v-loading="chartsLoading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(0, 0, 0, 0.3)"
              :time1="this.value2[0]"
              :time2="this.value2[1]"
              :checkType="checkType1"
              :commonData="tableData1"
              @clickLegend="clickLegend"
            >
            </materialCharts>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
  
<script>
// const typeOptions = [
//   { name: "油石比", label: "0" },
//   { name: "上限", label: "1" },
//   { name: "下限", label: "2" },
//   { name: "目标", label: "3" },
// ];
// const typeOilstone = [
//   { name: "出料温度", label: "0" },
//   { name: "上限", label: "1" },
//   { name: "下限", label: "2" },
//   { name: "目标", label: "3" },
// ];
import vDatePicker from "@/components/public/v-DatePicker";

// import tree from "@/components/public/pitchManage_tree"; //左侧机构树
import tree from "@/components/stationProductionPage/pitchManage/tree"; //左侧机构树

import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import oilstoneCharts from "@/components/stationProductionPage/pitchManage/dataAnalysisManage/oilstoneCharts"; //油石比
import materialCharts from "@/components/stationProductionPage/pitchManage/dataAnalysisManage/materialCharts"; //温度

import formJs from "./regexDetail.js"; //新增弹框配置项

import {
  getUserCompanyTreeList, //左侧机构树接口
  getMixMaterialInfo, //主页面列表接口
  getStationmachineList, //拌合站列表
  getMachineListByStationId, //获取拌合机
  getAsphaltRecipeListByCompanyId, // 查询-沥青混合料类型下拉框
} from "@/api/request.js";

export default {
  name: "dayStatistics",
  data() {
    return {
      name: "dayStatistics", //按钮配置页面代号
      // yj_view: null, //查看按钮是否显示
      formData: {}, //新增编辑向后台传递对象
      sgcDataList: formJs.sgcDataList, //施工层位
      bhzDataList: [], //拌合站
      bhjDataList: [], //拌合机
      liqhDataList: [], //沥青混合料类型
      level: [],

      value2: "", //主页面日期筛选绑定值
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", //拌合站
        machineId: "", //拌合机
        fConstructionhorizon: "", // 施工层位
        fMixturetype: "", //  沥青混合料类型
        warningLevel: "", // 预警等级
        fCloseoperation: "", //闭合状态
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
      },

      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据

      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [], //树状图默认选中id
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      tableData: [],
      tableData1: [],
      tableDataOilstone: [],
      checkType: {
        全选: false,
        全不选: false,
        油石比: false,
        上限: true,
        下限: true,
        目标: true,
      },
      checkType1: {
        全选: false,
        全不选: false,
        出料温度: false,
        上限: true,
        下限: true,
        目标: true,
      },
      chartsLoading: true,
      // types: typeOptions,
      // typesOilstone: typeOilstone,

      typeData: [
        { text: "油石比", show: true },
        { text: "温度曲线", show: false },
      ],
      typeDataNum: null,
    };
  },
  components: {
    tree, //左侧组织机构数
    elBreadcrumb, //面包屑
    oilstoneCharts, //油石比图表
    materialCharts, //温度曲线
    vDatePicker,
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"))) {
      var data = JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"));
      this.getList.fCompanyid = data.fCompanyid; // 施工标段id
      this.getList.startDates = data.startDates; // 开始时间
      this.getList.endDates = data.endDates; // 截至时间
      this.getList.fConstructionhorizon = data.fConstructionhorizon; // 施工层位
      this.getList.fMixturetype = data.fMixturetype; //  沥青混合料类型
      this.getList.stationId = data.stationId;
      this.getList.machineId = data.machineId;

      this.getbhjDataMethods(this.getList.stationId);
    }
    if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    if (JSON.parse(sessionStorage.getItem("yjSmart-dayStatistics_checkData"))) {
      this.checkType = JSON.parse(
        sessionStorage.getItem("yjSmart-dayStatistics_checkData")
      );
    }
    if (JSON.parse(sessionStorage.getItem("yjSmart-dayStatistics_checkType1"))) {
      this.checkType1 = JSON.parse(
        sessionStorage.getItem("yjSmart-dayStatistics_checkType1")
      );
    }

    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },

  methods: {
    changeType(e, index) {
      console.log(e);
      for (let i in this.typeData) {
        if (parseFloat(i) === index) {
          this.typeData[i].show = true;
        } else {
          this.typeData[i].show = false;
        }
      }
      // console.log('切换',index);
      // if (index == 0) {
      //   this.typeDataNum = index;
      //   this.yj_searchForm(this.getList);
      // } else if (index == 1) {
      //   this.typeDataNum = index;
      //   this.yj_searchForm(this.getList);
      // } else {
      this.typeDataNum = index;
      this.yj_searchForm(this.getList);
      // }
    },

    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
      } else {
        // this.yj_view = true;
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "3", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
              this.mixingPlantList(0, {
                fCompanyid: this.treeData[0].fCompanyid,
              });
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-pitchManage_treeCheck")
              ).fShortname;

              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.getAsphaltRecipeListByCompanyId(this.getList.fCompanyid);
            this.mixingPlantList(0, this.getList);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.fCompanyid = data.fCompanyid;
      this.mixingPlantList(0, this.getList);
      this.getAsphaltRecipeListByCompanyId(this.getList.fCompanyid);
      this.yj_searchForm(this.getList); // 调用主页面列表接口
      this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
      this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
      this.getList.machineId = ""; // 拌和机编号
      this.value2 = [
        this.common.getDay(-6) + " " + "00:00:00",
        this.common.getDay(0) + " " + "23:59:59",
      ];
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      this.chartsLoading = true;
      window.sessionStorage.setItem(
        "yjSmart-pitchManage_getLists",
        JSON.stringify(data)
      );
      if (data.machineId != "") {
        getMixMaterialInfo(data)
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              this.chartsLoading = false;
              that.listLoading = false;
              that.tableData = {
                data: res.data.mixMaterialAsphaltInfo,
                type: this.checkType,
              };
              that.tableData1 = {
                data: res.data.mixMaterialTemperatureInfo,
                type: this.checkType1,
              };
            } else {
              this.chartsLoading = false;

              this.$message.error(res.msg);
              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      } else {
        if (JSON.parse(sessionStorage.getItem("yjSmart-dayStatistics_checkData"))) {
          var checkObj = JSON.parse(
            sessionStorage.getItem("yjSmart-dayStatistics_checkData")
          );
          if (
            checkObj.油石比 == true &&
            checkObj.上限 == true &&
            checkObj.下限 == true &&
            checkObj.目标 == true
          ) {
            checkObj.全选 = true;
            checkObj.全不选 = false;
          } else if (
            checkObj.油石比 == false &&
            checkObj.上限 == false &&
            checkObj.下限 == false &&
            checkObj.目标 == false
          ) {
            checkObj.全选 = false;
            checkObj.全不选 = true;
          } else {
            checkObj.全选 = false;
            checkObj.全不选 = false;
          }
          this.checkType = checkObj;
        } else {
          this.checkType = {
            全选: false,
            全不选: false,
            油石比: false,
            上限: true,
            下限: true,
            目标: true,
          };
        }
        if (JSON.parse(sessionStorage.getItem("yjSmart-dayStatistics_checkType1"))) {
          var checkObj1 = JSON.parse(
            sessionStorage.getItem("yjSmart-dayStatistics_checkType1")
          );
          if (
            checkObj1.温度曲线 == true &&
            checkObj1.上限 == true &&
            checkObj1.下限 == true &&
            checkObj1.目标 == true
          ) {
            checkObj1.全选 = true;
            checkObj1.全不选 = false;
          } else if (
            checkObj1.温度曲线 == false &&
            checkObj1.上限 == false &&
            checkObj1.下限 == false &&
            checkObj1.目标 == false
          ) {
            checkObj1.全选 = false;
            checkObj1.全不选 = true;
          } else {
            checkObj1.全选 = false;
            checkObj1.全不选 = false;
          }
          this.checkType1 = checkObj1;
        } else {
          this.checkType1 = {
            全选: false,
            全不选: false,
            温度曲线: false,
            上限: true,
            下限: true,
            目标: true,
          };
        }
        getMixMaterialInfo(data)
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;

              this.chartsLoading = false;
              that.listLoading = false;

              that.tableData = {
                data: res.data.mixMaterialAsphaltInfo,
                type: this.checkType,
              };
              that.tableData1 = {
                data: res.data.mixMaterialTemperatureInfo,
                type: this.checkType1,
              };
            } else {
              this.chartsLoading = false;

              this.$message.error(res.msg);
              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
    },
    getAsphaltRecipeListByCompanyId(id) {
      var data = {
        fCompanyid: id,
      };
      this.liqhDataList = [];
      getAsphaltRecipeListByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.asphaltRecipeList;
            this.liqhDataList = [
              {
                fItemName: "所有沥青混合料类型",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.liqhDataList.push({
                fItemName: item.fMixturetype,
                fItemValue: item.fMixturetype,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 获取拌合站数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "3", // 拌合站类型
      };

      this.bhzDataList = [];
      this.bhjDataList = [];
      getStationmachineList(data)
        .then((res) => {
          console.log(8787, res);
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            if (num == 0) {
              this.bhzDataList = [
                {
                  fItemName: "所有拌和站",
                  fItemValue: "",
                },
              ];
              arr.map((item) => {
                this.bhzDataList.push({
                  fItemName: item.fMachinename,
                  fItemValue: item.fMachineid,
                });
              });
            }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    selectBhz(e) {
      this.getList.machineId = "";
      this.getbhjDataMethods(e);
    },
    // 获取拌合机
    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    clickLegend(e) {
      this.checkType = e;
      window.sessionStorage.setItem(
        "yjSmart-dayStatistics_checkData",
        JSON.stringify(e)
      );
    },
    clickLegend1(e) {
      this.checkType = e;
      window.sessionStorage.setItem(
        "yjSmart-dayStatistics_checkType1",
        JSON.stringify(e)
      );
    },
    // checkChange(e) {
    //   window.sessionStorage.setItem(
    //     "yjSmart-dayStatistics_checkData",
    //     JSON.stringify(e)
    //   );
    //   this.yj_searchForm(this.getList);
    // },

    // 时间间隔
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
      this.value2 = [this.getList.startDates, this.getList.endDates];
      this.yj_searchForm(this.getList);
    },

    getDate() {
      if (JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"))) {
        var data = JSON.parse(sessionStorage.getItem("yjSmart-pitchManage_getLists"));
        this.getList.startDates = data.startDates; // 开始时间
        this.getList.endDates = data.endDates; // 截至时间
        this.getList.machineId = data.machineId; // 拌和机编号
        this.value2 = [this.getList.startDates, this.getList.endDates];
        this.xlsxName =
          this.getList.startDates +
          "至" +
          this.getList.endDates +
          "混凝土拌和站记录数据";
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间

        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];

        this.xlsxName =
          this.common.getDay(-6) +
          "至" +
          this.common.getDay(0) +
          " " +
          "23:59:59" +
          "混凝土拌和站记录数据";
      }
    },
  },
};
</script>
  
<style scoped lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.materialCharts {
  height: calc(100% - 110px);
  width: 100%;
}

.selectcheckbox {
  margin-left: 15px;
  height: 35px;
  margin-top: -5px;
}

.text_table {
  display: flex;
  flex-direction: column;
  .tab {
    display: flex;
    font-size: 14px;
    height: 30px;
    line-height: 30px;
    box-sizing: border-box;
    border-bottom: 2px solid #e4e7ed;
    padding: 0 0.16rem;

    .btn {
      margin-top: 4px;
      margin-right: 16px;
      width: 102px;
      height: 24px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-top-right-radius: 4px;
      border-top-left-radius: 4px;
    }
  }

  .charts {
    height: calc(100% - 30px);
  }
}
</style>
  